package com.bw.culture

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.common.base.BaseActivity
import com.bw.common.path.RouthPath
import com.bw.culture.databinding.ActivityCultureBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouthPath.PATH_CULTURE_PAGE)
@AndroidEntryPoint
class CultureActivity : BaseActivity<ActivityCultureBinding>() {

    @Autowired
    @JvmField
    var moduleType :String ="7"

    override fun initViews() {
        ARouter.getInstance().inject(this)
        initModuleFragment()
        //返回点击事件
        mDataBind.includePageTitle.ivBack.setOnClickListener {
            this.finish()
        }

    }

    override fun getLayoutId(): Int = R.layout.activity_culture

    private fun initModuleFragment(){
        when(moduleType){
            "7" ->{
                mDataBind.includePageTitle.tvTitle.text = "文化编辑"
                commitFragment(CultureEditFragment.newInstance(),moduleType)
            }
            "8"->{
                mDataBind.includePageTitle.tvTitle.text = "发布公告"
                commitFragment(SendNoticeFragment.newInstance(),moduleType)
            }
            "9" ->{
                mDataBind.includePageTitle.tvTitle.text = "文化管理"
                commitFragment(CultureManagerFragment.newInstance(),moduleType)
            }
            "10"->{
                mDataBind.includePageTitle.tvTitle.text = "公告管理"
                commitFragment(NoticeManagerFragment.newInstance(),moduleType)
            }


        }
    }

    /**
     * 提交fragment到当前的Activity
     */
    private fun commitFragment(moduleFragment: Fragment, fragmentTag:String){
        //1.获取FragmentManager对象
        var fm = supportFragmentManager
        //2.开启事务
        var fragmentTransaction = fm.beginTransaction()
        //3.提交事务
        fragmentTransaction.replace(R.id.fragment_container,moduleFragment,fragmentTag)
        fragmentTransaction.commit()
    }

}